package dice.sinanya.db.tools;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqliteUtil {
    private static final Logger logger = LogManager.getLogger(SqliteUtil.class.getName());
    Connection con;      //声明Connection对象
    Connection diceCon;      //声明Connection对象

    public Connection getConnection() {    //建立返回值为Connection的方法
        try {                             //加载数据库驱动
            Class.forName("org.sqlite.JDBC");
            con = DriverManager.getConnection("jdbc:sqlite:config.db");
            logger.info("SQLITE登陆数据库连接成功");
        } catch (SQLException | ClassNotFoundException e) {
            logger.error(e.getMessage(), e);
        }
        return con;           //按方法要求放回一个Connection对象
    }

    public Connection getDiceLogConnection() {    //建立返回值为Connection的方法
        try {                             //加载数据库驱动
            Class.forName("org.sqlite.JDBC");
            diceCon = DriverManager.getConnection("jdbc:sqlite:diceLog.db");
            logger.info("SQLITE日志数据库连接成功");
        } catch (SQLException | ClassNotFoundException e) {
            logger.error(e.getMessage(), e);
        }
        return diceCon;           //按方法要求放回一个Connection对象
    }
}
